package com.fh.controller.system.student;

import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.naming.ldap.PagedResultsControl;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fh.entity.system.User;
import com.fh.service.system.user.UserService;
import com.fh.util.*;
import com.google.gson.JsonArray;
import com.google.gson.annotations.JsonAdapter;
import com.sun.xml.internal.fastinfoset.stax.events.Util;
import net.sf.json.JSON;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.fh.controller.base.BaseController;
import com.fh.entity.Page;
import com.fh.entity.system.Role;
import com.fh.service.system.dictionaries.DictionariesService;
import com.fh.service.system.role.RoleService;
import com.fh.service.system.student.StudentService;

/**
 * 类名称：StudentController
 * 创建人：FH
 * 创建时间：2015-07-29
 */
@Controller
@RequestMapping(value="/student")
public class StudentController extends BaseController {

	String menuUrl = "student/list.do"; //菜单地址(权限用)
	@Resource(name="studentService")
	private StudentService studentService;

	@Resource(name="roleService")
	private RoleService roleService;

	@Resource(name="userService")
	private UserService userService;


	@Resource(name="dictionariesService")
	private DictionariesService dictionariesService;
	/**
	 * 新增
	 */
	@RequestMapping(value="/save")
	public ModelAndView save() throws Exception{
		logBefore(logger, "新增Student");
		if(!Jurisdiction.buttonJurisdiction(menuUrl, "add")){return null;} //校验权限
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("USER_ID", this.get32UUID());	//主键
		pd.put("STATUS","0");
		pd.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("USERNAME"), pd.getString("PASSWORD")).toString());

		studentService.save(pd);

		mv.addObject("msg", "success");
//		mv.setViewName("/system/student/student_list");


		Page page=new Page();
		try{
			pd = this.getPageData();
			page.setPd(pd);
			List<PageData>	varList = studentService.list(page);	//列出Student列表
			/*for (PageData pageData : varList) {
				if (Util.isEmptyString(pageData.getString("DEPARTMENT_ID"))) {
				} else {
					PageData pdp = new PageData();
					pdp.put("BIANMA", pageData.getString("DEPARTMENT_ID"));
					String DEPARTMENT_NAME = dictionariesService.findByBM(pdp).getString("NAME");
					pageData.put("DEPARTMENT_ID", DEPARTMENT_NAME);
				}
				if ( Util.isEmptyString(pageData.getString("PROFESSION_ID"))) {
				} else {
					PageData pdp = new PageData();
					pdp.put("BIANMA", pageData.getString("PROFESSION_ID"));
					String PROFESSION_NAME = dictionariesService.findByBM(pdp).getString("NAME");
					pageData.put("PROFESSION_ID", PROFESSION_NAME);
				}
				if (Util.isEmptyString(pageData.getString("CLASSES_ID"))) {
				} else {
					PageData pdp = new PageData();
					pdp.put("BIANMA", pageData.getString("CLASSES_ID"));
					String CLASSES_NAME = dictionariesService.findByBM(pdp).getString("NAME");
					pageData.put("CLASSES_ID", CLASSES_NAME);
				}

			}*/

			mv.setViewName("system/student/student_list");
			mv.addObject("varList", varList);
			mv.addObject("pd", pd);
			mv.addObject(Const.SESSION_QX,this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}



		return mv;
	}

	/**
	 * 判断用户名是否存在
	 */
	@RequestMapping(value="/hasU")
	@ResponseBody
	public Object hasU(){
		Map<String,String> map = new HashMap<String,String>();
		String errInfo = "success";
		PageData pd = new PageData();
		try{
			pd = this.getPageData();
			if(studentService.findByUsername(pd) != null){
				errInfo = "error";
			}
		} catch(Exception e){
			logger.error(e.toString(), e);
		}
		map.put("result", errInfo);				//返回结果
		return AppUtil.returnObject(new PageData(), map);
	}


	/**
	 * 获取专业
	 */
	@RequestMapping(value="/getNext")
	@ResponseBody			// 将内容或对象作为 HTTP 响应正文返回，并调用适合HttpMessageConverter的Adapter转换对象，写入输出流。
	public Map getNext(){
		PageData pd = new PageData();
		Map josnMap = new HashMap();
		pd = this.getPageData();

		List<PageData> tasks = null;
		try {
			tasks = dictionariesService.dictlistPagebyp_bm(pd);
			List list = new ArrayList();
			if(tasks.size()>0){
				for(PageData task:tasks)
				{
					Map taskMap=new HashMap();
					taskMap.put("BIANMA", task.getString("BIANMA"));
					taskMap.put("NAME", task.get("NAME"));
					list.add(taskMap);
				}
			}
			else{
				Map taskMap=new HashMap();
				taskMap.put("BIANMA", null);
				taskMap.put("NAME", null);
				list.add(taskMap);
			}
			josnMap.put("tasks", list);
		} catch (Exception e) {
			e.printStackTrace();
		}


		return josnMap;

	}


	/**
	 * 删除
	 */
	@RequestMapping(value="/delete")
	public void delete(PrintWriter out){
		logBefore(logger, "删除Student");
		if(!Jurisdiction.buttonJurisdiction(menuUrl, "del")){return;} //校验权限
		PageData pd = new PageData();
		try{
			pd = this.getPageData();
			studentService.delete(pd);
			out.write("success");
			out.close();
		} catch(Exception e){
			logger.error(e.toString(), e);
		}

	}

	/**
	 * 修改
	 */
	@RequestMapping(value="/edit")
	public ModelAndView edit() throws Exception{
		logBefore(logger, "修改Student");
		if(!Jurisdiction.buttonJurisdiction(menuUrl, "edit")){return null;} //校验权限
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("PASSWORD", new SimpleHash("SHA-1", pd.getString("USERNAME"), pd.getString("PASSWORD")).toString());
		pd.put("STATUS", pd.getString("STATUS"));
		studentService.edit(pd);
		mv.addObject("msg", "success");
//		mv.setViewName("/system/student/student_list");


		Page page=new Page();
		try{
			pd = this.getPageData();
			page.setPd(pd);
			List<PageData>	varList = studentService.list(page);	//列出Student列表


			mv.setViewName("system/student/student_list");
			mv.addObject("varList", varList);
			mv.addObject("pd", pd);
			mv.addObject(Const.SESSION_QX,this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}





		return mv;
	}

	/**
	 * 列表
	 */
	@RequestMapping(value="/list")
	public ModelAndView list(Page page){
		logBefore(logger, "列表Student");
		//if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;} //校验权限
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		try{
			pd = this.getPageData();
			page.setPd(pd);
			List<PageData>	varList = studentService.list(page);	//列出Student列表

			System.out.println("varList = [" + varList + "]");
			mv.setViewName("system/student/student_list");
			mv.addObject("varList", varList);
			mv.addObject("pd", pd);
			mv.addObject(Const.SESSION_QX,this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}
		return mv;
	}

	/**
	 * 去新增页面
	 */
	@RequestMapping(value="/goAdd")
	public ModelAndView goAdd(Page page){
		logBefore(logger, "去新增Student页面");
		ModelAndView mv = this.getModelAndView();
		try {
			PageData pd = new PageData();
			pd.put("P_BM", "YX");
			List<PageData> roleList1 = dictionariesService.dictlistPagebyp_bm(pd);
			mv.addObject("roleList1", roleList1);
			mv.setViewName("system/student/student_edit");
			mv.addObject("msg", "save");
			mv.addObject("title","用户增加");
			mv.addObject("pd", pd);
		} catch (Exception e) {
			logger.error(e.toString(), e);
		}

		return mv;
	}

	/**
	 * 去修改页面
	 */
	@RequestMapping(value="/goEdit")
	public ModelAndView goEdit(){
		logBefore(logger, "去修改Student页面");
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();			//包含STUDENT_ID
		try {
			PageData pdp = new PageData();
			pdp.put("P_BM", "YX");
			List<PageData> roleList1 = dictionariesService.dictlistPagebyp_bm(pdp);
			String DEPARTMENT_ID = studentService.findById(pd).getString("DEPARTMENT_ID");
			pdp.put("P_BM", DEPARTMENT_ID);
			List<PageData> roleList2 = dictionariesService.dictlistPagebyp_bm(pdp);
			String PROFESSION_ID = studentService.findById(pd).getString("PROFESSION_ID");
			pdp.put("P_BM", PROFESSION_ID);
			List<PageData> roleList3 = dictionariesService.dictlistPagebyp_bm(pdp);
			mv.addObject("roleList1", roleList1);
			mv.addObject("roleList2", roleList2);
			mv.addObject("roleList3", roleList3);
			pd = studentService.findById(pd);    //根据ID读取
			mv.setViewName("system/student/student_edit");
			mv.addObject("msg", "edit");
			mv.addObject("title", "用户修改");
			mv.addObject("pd", pd);
		} catch (Exception e) {
			logger.error(e.toString(), e);
		}
		return mv;
	}

	/**
	 * 批量删除
	 */
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public Object deleteAll() {
		logBefore(logger, "批量删除Student");
		if(!Jurisdiction.buttonJurisdiction(menuUrl, "dell")){return null;} //校验权限
		PageData pd = new PageData();
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			pd = this.getPageData();
			List<PageData> pdList = new ArrayList<PageData>();
			String DATA_IDS = pd.getString("DATA_IDS");
			if(null != DATA_IDS && !"".equals(DATA_IDS)){
				String ArrayDATA_IDS[] = DATA_IDS.split(",");
				studentService.deleteAll(ArrayDATA_IDS);
				pd.put("msg", "ok");
			}else{
				pd.put("msg", "no");
			}
			pdList.add(pd);
			map.put("list", pdList);
		} catch (Exception e) {
			logger.error(e.toString(), e);
		} finally {
			logAfter(logger);
		}
		return AppUtil.returnObject(pd, map);
	}

	/*
	 * 导出到excel
	 * @return
	 */
	@RequestMapping(value="/excel")
	public ModelAndView exportExcel(){
		logBefore(logger, "导出Student到excel");
		if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;}
		ModelAndView mv = new ModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		try{
			Map<String,Object> dataMap = new HashMap<String,Object>();
			List<String> titles = new ArrayList<String>();
			titles.add("学号，用户名");	//1
			titles.add("真实姓名");	//2
			titles.add("密码");	//3
			titles.add("电子邮件");	//4
			titles.add("qq");	//5
			titles.add("联系电话");	//6
			titles.add("性别");	//7
			titles.add("地址");	//8
			titles.add("0:未选,1待确认,2确认选题");	//9
			titles.add("用户状态     用户状态 1正常状态 2 删除至回收站 3锁定");	//10
			titles.add("开始使用日期");	//11
			titles.add("结束使用日期");	//12
			titles.add("注册日期");	//13
			titles.add("最后一次登陆日期");	//14
			titles.add("最后一次登陆IP");	//15
			titles.add("院系ID");	//16
			titles.add("专业ID");	//17
			titles.add("班级ID");	//18
			dataMap.put("titles", titles);
			List<PageData> varOList = studentService.listAll(pd);
			List<PageData> varList = new ArrayList<PageData>();
			for(int i=0;i<varOList.size();i++){
				PageData vpd = new PageData();
				vpd.put("var1", varOList.get(i).getString("USERNAME"));	//1
				vpd.put("var2", varOList.get(i).getString("NAME"));	//2
				vpd.put("var3", varOList.get(i).getString("PASSWORD"));	//3
				vpd.put("var4", varOList.get(i).getString("EMAIL"));	//4
				vpd.put("var5", varOList.get(i).getString("QQ"));	//5
				vpd.put("var6", varOList.get(i).getString("PHONE"));	//6
				vpd.put("var7", varOList.get(i).getString("SEX"));	//7
				vpd.put("var8", varOList.get(i).getString("ADDR"));	//8
				vpd.put("var9", varOList.get(i).getString("CHOICE_STATE"));	//9
				vpd.put("var10", varOList.get(i).getString("STATUS"));	//10
				vpd.put("var11", varOList.get(i).getString("TIME_BEGIN"));	//11
				vpd.put("var12", varOList.get(i).getString("TIME_END"));	//12
				vpd.put("var13", varOList.get(i).getString("TIME_REG"));	//13
				vpd.put("var14", varOList.get(i).getString("LAST_LOGINTIME"));	//14
				vpd.put("var15", varOList.get(i).getString("LAST_LOGINIP"));	//15
				vpd.put("var16", varOList.get(i).getString("DEPARTMENT_ID"));	//16
				vpd.put("var17", varOList.get(i).getString("PROFESSION_ID"));	//17
				vpd.put("var18", varOList.get(i).getString("CLASSES_ID"));	//18
				varList.add(vpd);
			}
			dataMap.put("varList", varList);
			ObjectExcelView erv = new ObjectExcelView();
			mv = new ModelAndView(erv,dataMap);
		} catch(Exception e){
			logger.error(e.toString(), e);
		}
		return mv;
	}

	/**
	 * 打开上传EXCEL页面
	 */
	@RequestMapping(value="/goUploadExcel")
	public ModelAndView goUploadExcel()throws Exception{
		ModelAndView mv = this.getModelAndView();
		try {
			PageData pd = new PageData();
			pd.put("P_BM", "YX");
			List<PageData> roleList1 = dictionariesService.dictlistPagebyp_bm(pd);
			mv.addObject("roleList1", roleList1);
			mv.addObject("pd", pd);
		} catch (Exception e) {
			logger.error(e.toString(), e);
		}


		mv.setViewName("system/student/uploadexcel");
		return mv;
	}

	/**
	 * 下载模版
	 */
	@RequestMapping(value="/downExcel")
	public void downExcel(HttpServletResponse response)throws Exception{

		FileDownload.fileDownload(response, PathUtil.getClasspath() + Const.FILEDOWNPATH + "students.xls", "students.xls");

	}

	/**
	 * 从EXCEL导入到数据库
	 */
	@RequestMapping(value="/readExcel")
	public ModelAndView readExcel(
			@RequestParam(value="excel",required=false) MultipartFile file, HttpServletRequest request
	) throws Exception{
		System.out.println("从EXCEL导入到数据库");

		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();

		int failCount=0;					//导入失败计数
		int successCount=0;					//导入成功计数

		if(!Jurisdiction.buttonJurisdiction(menuUrl, "add")){return null;}
		if (null != file && !file.isEmpty()) {
			String filePath = PathUtil.getClasspath() + Const.FILEPATHFILE;								//文件上传路径
			String fileName =  FileUpload.fileUp(file, filePath, "students");							//执行上传
			List<PageData> listPd = (List)ObjectExcelRead.readExcel(filePath, fileName, 2, 0, 0);	//执行读EXCEL操作,读出的数据导入List 2:从第3行开始；0:从第A列开始；0:第0个sheet
//			PageData pageData = this.getPageData();
			String DEPARTMENT_ID = request.getParameter("DEPARTMENT_ID");
			String PROFESSION_ID = request.getParameter("PROFESSION_ID");
			String CLASSES_ID = request.getParameter("CLASSES_ID");
			String OVERLAP = request.getParameter("OVERLAP");
			/*存入数据库操作======================================*/
//			pd.put("RIGHTS", "");					//权限
			pd.put("LAST_LOGINTIME", "");				//最后登录时间
			pd.put("LAST_LOGINIP", "");						//IP
			pd.put("CHOICE_STATE", "");						//选题状态
			pd.put("STATUS", "0");						//状态
			pd.put("TIME_BEGIN", "");						//
			pd.put("TIME_END", "");						//
			pd.put("TIME_REG", "");						//
//			pd.put("PASSWORD","123456");	//默认密码123456
			pd.put("PASSWORD", new SimpleHash("SHA-1", "123456", pd.getString("PASSWORD")).toString());


//			List<Role> roleList = roleService.listAllERRoles();	//列出所有二级角色

//			pd.put("ROLE_ID", roleList.get(0).getROLE_ID());	//设置角色ID为随便第一个
			/**
			 * var0:USERNAME
			 * VAR1:NAME
			 * VAR2:EMAIL
			 * VAR3:QQ
			 * VAR4:PHONE
			 * VAR5:SEX
			 * VAR6:ADDR
			 * VAR7:PASSWORD
			 */

			for(int i=0;i<listPd.size();i++){
				pd.put("USER_ID", this.get32UUID());										//ID
				pd.put("USERNAME", listPd.get(i).getString("var0"));							//姓名

				pd.put("NAME", listPd.get(i).getString("var1"));
				pd.put("EMAIL", listPd.get(i).getString("var2"));
				pd.put("QQ", listPd.get(i).getString("var3"));
				pd.put("PHONE", listPd.get(i).getString("var4"));
				pd.put("SEX", listPd.get(i).getString("var5"));
				pd.put("ADDR", listPd.get(i).getString("var6"));
				pd.put("DEPARTMENT_ID",DEPARTMENT_ID);
				pd.put("PROFESSION_ID", PROFESSION_ID);
				pd.put("CLASSES_ID", CLASSES_ID);
				pd.put("PASSWORD", new SimpleHash("SHA-1", listPd.get(i).getString("var0").toString(), listPd.get(i).getString("var7").toString()).toString());

				if(studentService.findByUsername(pd) != null) {                                        //判断用户名是否重复
					if (OVERLAP.equals("true")) {                        //覆盖
						studentService.editByUsername(pd);
						successCount++;
						continue;
					} else {
						failCount++;
						continue;
					}

				}
				studentService.save(pd);
				successCount++;

			}
			/*存入数据库操作======================================*/
			System.out.println("successCont = [" + successCount + "], failCount = [" + failCount + "]");

			mv.addObject("msg","success");
		}

		Page page=new Page();
		try{
			pd = this.getPageData();
			page.setPd(pd);
			List<PageData>	varList = studentService.list(page);	//列出Student列表
			/*for (PageData pageData : varList) {
				if (Util.isEmptyString(pageData.getString("DEPARTMENT_ID"))) {
				} else {
					PageData pdp = new PageData();
					pdp.put("BIANMA", pageData.getString("DEPARTMENT_ID"));
					String DEPARTMENT_NAME = dictionariesService.findByBM(pdp).getString("NAME");
					pageData.put("DEPARTMENT_ID", DEPARTMENT_NAME);
				}
				if ( Util.isEmptyString(pageData.getString("PROFESSION_ID"))) {
				} else {
					PageData pdp = new PageData();
					pdp.put("BIANMA", pageData.getString("PROFESSION_ID"));
					String PROFESSION_NAME = dictionariesService.findByBM(pdp).getString("NAME");
					pageData.put("PROFESSION_ID", PROFESSION_NAME);
				}
				if (Util.isEmptyString(pageData.getString("CLASSES_ID"))) {
				} else {
					PageData pdp = new PageData();
					pdp.put("BIANMA", pageData.getString("CLASSES_ID"));
					String CLASSES_NAME = dictionariesService.findByBM(pdp).getString("NAME");
					pageData.put("CLASSES_ID", CLASSES_NAME);
				}

			}
*/
//			mv.setViewName("system/student/student_list");
			mv.setViewName("system/student/uploadexcel");
			mv.addObject("successCount", successCount);
			mv.addObject("failCount", failCount);
			System.out.println("successCount = [" + successCount + "], failCount = [" + failCount + "]");

			mv.addObject("varList", varList);
			mv.addObject("pd", pd);
			mv.addObject(Const.SESSION_QX,this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}

//		mv.setViewName("save_result");
		return mv;
	}

	/* ===============================权限================================== */
	public Map<String, String> getHC(){
		Subject currentUser = SecurityUtils.getSubject();  //shiro管理的session
		Session session = currentUser.getSession();
		return (Map<String, String>)session.getAttribute(Const.SESSION_QX);
	}
	/* ===============================权限================================== */

	@InitBinder
	public void initBinder(WebDataBinder binder){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
	}




/*
* 2015-08-27 17:18:31起 增加以下项目
* 学生登录后个人信息的查改等
*
* */


	@RequestMapping(value="/student_info")
	public ModelAndView student_info(Page page){
		logBefore(logger, "个人资料");
//		if(!Jurisdiction.buttonJurisdiction("student/student_info.do", "cha")){return null;} //校验权限
		System.out.println("Jurisdiction.buttonJurisdiction(\"student/student_info.do\", \"cha\") = [" + Jurisdiction.buttonJurisdiction("student/student_info.do", "cha") + "]");

		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();

		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();

		User user = (User)session.getAttribute(Const.SESSION_USER);
		try {
			pd.put("USER_ID",user.getUSER_ID());
			pd = studentService.findById(pd);
			System.out.println("pd.toString() = [" + pd.toString() + "]");

			System.out.println("pd = [" + pd + "]");

			PageData pdp = new PageData();
			pdp.put("BIANMA",pd.getString("DEPARTMENT_ID"));
			String DEPARTMENT_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			pdp.put("BIANMA",pd.getString("PROFESSION_ID"));
			String PROFESSION_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			pdp.put("BIANMA", pd.getString("CLASSES_ID"));
			String CLASSES_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			mv.addObject("DEPARTMENT_NAME", DEPARTMENT_NAME);
			mv.addObject("PROFESSION_NAME", PROFESSION_NAME);
			mv.addObject("CLASSES_NAME", CLASSES_NAME);


			System.out.println("page = [" + DEPARTMENT_NAME + "]");
			System.out.println("page = [" + PROFESSION_NAME + "]");
			System.out.println("page = [" + CLASSES_NAME + "]");

			mv.addObject("title", "个人资料");
			mv.setViewName("system/student/student_info");
			mv.addObject("pd", pd);
//			mv.addObject(Const.SESSION_QX, this.getHC());	//按钮权限
//			System.out.println("HC = [" + this.getHC() + "]");
		} catch(Exception e){
			logger.error(e.toString(), e);
		}


		return mv;
	}




	@RequestMapping(value="/goStudentEditInfo")
	public ModelAndView goStudentEditInfo(Page page){
		logBefore(logger, "个人资料修改");
//		if(!Jurisdiction.buttonJurisdiction("student/student_info.do", "cha")){return null;} //校验权限

		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();

		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();

		User user = (User)session.getAttribute(Const.SESSION_USER);
		try {
			pd.put("USER_ID",user.getUSER_ID());
			pd = studentService.findById(pd);
			PageData pdp = new PageData();
			pdp.put("BIANMA", pd.getString("DEPARTMENT_ID"));
			String DEPARTMENT_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			pdp.put("BIANMA", pd.getString("PROFESSION_ID"));
			String PROFESSION_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			pdp.put("BIANMA", pd.getString("CLASSES_ID"));
			String CLASSES_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			mv.addObject("DEPARTMENT_NAME", DEPARTMENT_NAME);
			mv.addObject("PROFESSION_NAME", PROFESSION_NAME);
			mv.addObject("CLASSES_NAME", CLASSES_NAME);
			mv.addObject("msg", "studentEditInfo");

			mv.addObject("title", "修改资料");
			mv.setViewName("system/student/student_editInfo");
			System.out.println("page = [" + pd + "]");
			mv.addObject("pd", pd);
			System.out.println("pd1=" + pd);

//			mv.addObject(Const.SESSION_QX, this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}


		return mv;
	}


	/**
	 * 修改学生个人资料
	 */
	@RequestMapping(value="/studentEditInfo")
	public ModelAndView studentEditInfo() throws Exception{
		logBefore(logger, "修改Student");
//		if(!Jurisdiction.buttonJurisdiction(menuUrl, "edit")){return null;} //校验权限
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		studentService.edit(pd);


		try {
			pd = studentService.findById(pd);
			PageData pdp = new PageData();
			pdp.put("BIANMA", pd.getString("DEPARTMENT_ID"));
			String DEPARTMENT_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			pdp.put("BIANMA", pd.getString("PROFESSION_ID"));
			String PROFESSION_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			pdp.put("BIANMA", pd.getString("CLASSES_ID"));
			String CLASSES_NAME=dictionariesService.findByBM(pdp).getString("NAME");
			mv.addObject("DEPARTMENT_NAME", DEPARTMENT_NAME);
			mv.addObject("PROFESSION_NAME", PROFESSION_NAME);
			mv.addObject("CLASSES_NAME", CLASSES_NAME);
			mv.setViewName("system/student/student_info");
			mv.addObject("pd", pd);
//			mv.addObject(Const.SESSION_QX, this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}


		return mv;
	}

//goModifyStudentPasswd

	@RequestMapping(value = "/goModifyStudentPasswd")
	public ModelAndView goModifyStudentPasswd() {
		logBefore(logger, "ModifyStudentPassword");

		ModelAndView mv =this.getModelAndView();
//		mv.setViewName("system/student/student_MiMa");

		mv.addObject("pd", this.getPageData());

		mv.setViewName("system/student/student_PswdModify");
		System.out.println("aaa");

		return mv;
	}

	@RequestMapping(value = "/chkpwd")
	@ResponseBody
	public Object chkpwd() throws Exception {
		logBefore(logger, "chkpwd");

		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user = (User)session.getAttribute(Const.SESSION_USER);

		Map<String,String> map = new HashMap<String,String>();
		PageData pd = new PageData();
		pd = this.getPageData();
		System.out.println(pd.getString("KEYDATA"));
		String errInfo = "";
		String KEYDATA[] = pd.getString("KEYDATA").split("#");
		String USER_ID=user.getUSER_ID();
		String USERNAME=user.getUSERNAME();
		System.out.println("USER_ID"+USER_ID);
		System.out.println("USERNAME"+USERNAME);
		String OLDPASSWORD=KEYDATA[0];
		PageData pageData = new PageData();
		pageData.put("USER_ID", USER_ID);
		pageData.put("USERNAME", USERNAME);
		String passwd = new SimpleHash("SHA-1", USERNAME, OLDPASSWORD).toString();	//密码加密

		pageData.put("PASSWORD", passwd);
		System.out.println("pageData" + pageData);
		if (userService.getUserByNameAndPwd(pageData) != null) {				//校验成功，改密码
			errInfo = "success";
			passwd = new SimpleHash("SHA-1", USERNAME, KEYDATA[1]).toString();	//密码加密
			pageData.put("PASSWORD",passwd);
			System.out.println("" + userService.findByUId(pageData));
			userService.modifyPassword(pageData);
			System.out.println("" + userService.findByUId(pageData));

		}else errInfo="error";

		map.put("result", errInfo);
		return AppUtil.returnObject(new PageData(), map);
	}


/*

	@RequestMapping(value = "modifyStudentPasswd")
	public ModelAndView modifyStudentPasswd() {
		ModelAndView mv = this.getModelAndView();
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();

		User user = (User)session.getAttribute(Const.SESSION_USER);

		PageData pd = this.getPageData();

		return mv;
	}
*/









}
